/* eslint-disable react/no-unused-state */
import { Component } from "react"
import { View,Input,Textarea,Button } from "@tarojs/components"
import Dialog from "./Dialog"
import "./AddQuestion.less"

export default class AddQuestion extends Component{
    state = {
        title: "",
        des: ""
    }
    btnCancel(){
        //调用父组件传递来的属性方法
        this.props.closeQuestion();
    }
    changeTitle(e){
        this.setState({title:e.target.value})
    }
    changeDes(e){
        this.setState({des:e.target.value})
    }    
    btnOk(){
        if (this.state.title && this.state.des){
            //调用父组件传递来的receiveQuestion
            this.props.receiveQuestion(this.state)
        }else{
            // eslint-disable-next-line no-undef
            Taro.showToast({
                title:"请输入标题或者描述...",
                icon:"none"
            })
        }
    }
    render(){
        return(
            <Dialog className='dialog_'>
                <View className='add-question'>
                    <View className='question-body' >
                        <Input onInput={this.changeTitle.bind(this)} placeholder='请输入提问内容..' className='question-title'></Input>
                        <Textarea onInput={this.changeDes.bind(this)}  placeholder='请输入提问描述..' className='question-des'></Textarea>
                        <View className='btn-group'>
                            <Button onClick={this.btnOk.bind(this)} className='btn-question ok'>确定</Button>
                            <Button onClick={this.btnCancel.bind(this)} className='btn-question cancel'>取消</Button>
                            <View> {1+1===2 ? '1' : '2'}</View>
                        </View>
                    </View>
                </View>
            </Dialog>
        )
        
    }
}